    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.webbapps.cormac_susilo.core;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * Represents a user in the model
 * @author simon, tor
 */
@Entity
@Table(name = "Users")
public class User extends AbstractEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO )
    private long id;
    
    @Column(unique=true, nullable = false, length=32)
    private String name;
    @Column(nullable = false, length = 32)
    private String password;    //plaintext
    private String avatar;      // http
    private String givenname; //
    private String familyname;
    private String email;
    private double total_distance; // meters
    private double total_time;     // seconds
    
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user")
    List<Run> runs;
    
    public User(){
    }

    public User(String name, String password, String avatar, String givenname, String familyname, String email) {
        this.name = name;
        this.password = password;
        this.avatar = avatar;
        this.givenname = givenname;
        this.familyname = familyname;
        this.email = email;
    }
    
    public User(String name, String password, String avatar) {
        this.name = name;
        this.password = password;
        this.avatar = avatar;
    }
    public User(String name, String password){
        this.name = name;
        this.password = password;
    }
    
    @Override
    public Long getId() {
        return id;
    }
    
    public String getName(){
        return this.name;
    }

    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getPassword() {
        return password;
    }

    
    public void setPassword(String password) {
        this.password = password;
    }

    
    public String getAvatar() {
        return avatar;
    }

    
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    
    public double getTotal_distance() {
        return total_distance;
    }

    
    public void setTotal_distance(double total_distance) {
        this.total_distance = total_distance;
    }

    
    public double getTotal_time() {
        return total_time;
    }

    
    public void setTotal_time(double total_time) {
        this.total_time = total_time;
    }
    
    public void setRuns(List<Run> runs) {
        this.runs = runs;
    }
    
    public List<Run> getRuns() {
        return this.runs;
    }

    public String getGivenname() {
        return givenname;
    }

    public void setGivenname(String givenname) {
        this.givenname = givenname;
    }

    public String getFamilyname() {
        return familyname;
    }

    public void setFamilyname(String familyname) {
        this.familyname = familyname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}
